package com.hdax.easybuy.service;

import com.hdax.easybuy.entity.Product;
import com.hdax.easybuy.entity.ProductCategory;
import com.hdax.easybuy.entity.Users;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

@Service
public class ProductService {

    @PersistenceContext
    private EntityManager entityManager;

    public List<ProductCategory> queryyijiByTypeId() {
        String jpql = "from ProductCategory p where p.type=1";
        List resultList = entityManager.createQuery(jpql).getResultList();
        return resultList;
    }
    public List<Product> queryProduct(int fid) {
        String jpql = "from Product p where p.categoryLevel1Id=:a";
        Query query = entityManager.createQuery(jpql);
        query.setParameter("a",fid);
        return query.getResultList();
    }

    public List<ProductCategory> queryyijiByTypeIds(List<Integer> list) {
        String jpql = "from ProductCategory p where p.parentId in(:ids)";

        Query query = entityManager.createQuery(jpql);
        query.setParameter("ids",list);
        return query.getResultList();
    }
    public List<ProductCategory> queryyijiByTypeIds1(int id) {
        String jpql = "from ProductCategory p where p.parentId =:a";

        Query query = entityManager.createQuery(jpql);
        query.setParameter("a",id);
        return query.getResultList();
    }
}
